package ru.classbase.dbdumper

import org.slf4j.Logger
import org.slf4j.LoggerFactory.getLogger
import ru.classbase.dbdumper.model.CompressionType
import ru.classbase.dbdumper.model.CompressionType.NONE
import ru.classbase.dbdumper.model.OutputFormat
import ru.classbase.dbdumper.model.TableName

inline fun <reified T> T.logger(): Logger = getLogger(T::class.java)

fun getFileExtension(outputFormat: OutputFormat, compressionType: CompressionType): String {
    if (compressionType == NONE) {
        return outputFormat.ext
    }

    return compressionType.ext
}

fun getMimeType(outputFormat: OutputFormat, compressionType: CompressionType): String {
    if (compressionType == NONE) {
        return outputFormat.mimeType
    }

    return compressionType.mimeType
}

fun tableNameMatch(tableName: TableName, schemaProps: SchemaProperties): Boolean {
    val include = schemaProps.includeTables.isEmpty() || schemaProps.includeTables.any { it.matches(tableName) }
    val exclude = schemaProps.excludeTables.isEmpty() || schemaProps.excludeTables.none { it.matches(tableName) }

    return include && exclude
}